<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui">


    <ui:define name="content">


        <h:form  >
            <p:growl />



            <p:panel header="Item Suppliers">
                <p:defaultCommand target="btnAdd"/>
                <h:panelGrid columns="7" >
                    <p:outputLabel value="Supplier "/>
                    <p:spacer width="30" height="1" ></p:spacer>
                    <p:autoComplete converter="deal"  id="lstSelect"   
                                    value="#{itemsDistributorsController.currentInstituion}" 
                                    forceSelection="true"
                                    style="min-width: 223px" completeMethod="#{dealerController.completeDealor}"   
                                    var="myItem" itemValue="#{myItem}" itemLabel="#{myItem.name}" >
                        <p:column headerText="Item">
                            <h:outputLabel value="#{myItem.name}" ></h:outputLabel>
                        </p:column>

                        <f:ajax event="itemSelect" render="gpDetail" execute="lstSelect" >
                        </f:ajax>
                    </p:autoComplete>
                    <p:spacer width="60" height="1" ></p:spacer>

                    <p:autoComplete converter="itemcon" value="#{itemsDistributorsController.currentItem}" 
                                    forceSelection="true" id="acItem"
                                    completeMethod="#{itemController.completeAmpItem}" var="vt" itemLabel="#{vt.name}" itemValue="#{vt}" >
                        <p:column headerText="Name" >
                            <h:outputLabel value="#{vt.name}" ></h:outputLabel>
                        </p:column>
                        <p:column headerText="Code" >
                            <h:outputLabel value="#{vt.code}" ></h:outputLabel>
                        </p:column>
                    </p:autoComplete>  
                    <p:watermark for="acItem" value="Select Item to Add" ></p:watermark>
                    <h:commandButton id="btnAdd" value="Add" action="#{itemsDistributorsController.addToPackage()}">
                    </h:commandButton>


                </h:panelGrid>


                <h:panelGroup id="gpDetail" >
                    <p:dataTable  scrollable="true" scrollHeight="450" id="packageItem" 
                                  value="#{itemsDistributorsController.items}" var="i"
                                  >
                        <f:facet name="header" >
                            <h:outputLabel value="Items Supplied by Selected Supplier" ></h:outputLabel>
                        </f:facet>
                        <p:column headerText="Item Name">
                            <h:outputLabel value="#{i.item.name}"/> 
                        </p:column>
                        <p:column headerText="Item Code">
                            <h:outputLabel value="#{i.item.code}"/> 
                        </p:column>
                        <p:column headerText="Item BarCode">
                            <h:outputLabel value="#{i.item.barcode}"/> 
                        </p:column>
                        <p:column headerText="Action">
                            <p:commandButton ajax="false" value="Remove" action="#{itemsDistributorsController.removeFromPackage()}" >
                                <f:setPropertyActionListener target="#{itemsDistributorsController.current}" value="#{i}"/>
                            </p:commandButton>
                        </p:column>
                    </p:dataTable>                              
                </h:panelGroup>
            </p:panel>





        </h:form>

    </ui:define>

</ui:composition>
